const fs = require("fs")

async function getArticles() {
  const res = await (await fetch("https://fuyouplus.cn/Api/getArticle")).json()
  return res
}
function createContent(item) {
  const settingContent = `<blog-title>${item.article_title}</blog-title>
<blog-intro></blog-intro>
<blog-img>${item.article_headerImg}</blog-img>
<blog-createTime>${new Date(Number(item.article_addTime))
    .toLocaleDateString()
    .replaceAll("/", "-")}</blog-createTime>
<blog-updateTime></blog-updateTime>
<blog-tag>${item.article_tag}</blog-tag>
<blog-category>${item.article_classify}</blog-category>
|||

`
  return settingContent + item.article_content
}
async function main() {
  const { data } = await getArticles()
  data.forEach((item, index) => {
    fs.writeFile(`articles/${index + 1}.md`, createContent(item), () => {
      console.log(`${index + 1}.md completed`)
    })
  })
}

main()
